package com.sishu.njrtsdms.controller;

import com.sishu.njrtsdms.domain.core.Groups;
import com.sishu.njrtsdms.domain.core.R;
import com.sishu.njrtsdms.domain.dto.TcpDeclareBelongYearConfigDTO;
import com.sishu.njrtsdms.domain.vo.TcpDeclareBelongYearConfigVO;
import com.sishu.njrtsdms.service.TcpDeclareBelongYearConfigService;
import lombok.extern.slf4j.Slf4j;
import org.jooq.types.ULong;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Validated
@RestController
@RequestMapping("/tcpConfig")
@Slf4j
public class TcpConfigController {

    private final TcpDeclareBelongYearConfigService tcpDeclareBelongYearConfigService;

    public TcpConfigController(TcpDeclareBelongYearConfigService
                                       tcpDeclareBelongYearConfigService) {
        this.tcpDeclareBelongYearConfigService = tcpDeclareBelongYearConfigService;
    }

    @GetMapping("/declareBelongYear")
    public R<List<TcpDeclareBelongYearConfigVO>> listTcpDeclareBelongYearConfigs() {
        List<TcpDeclareBelongYearConfigVO> tcpDeclareBelongYearConfigVOList =
                tcpDeclareBelongYearConfigService.listTcpDeclareBelongYearConfigs();
        return R.ok(tcpDeclareBelongYearConfigVOList);
    }

    @PostMapping("/declareBelongYear")
    public R<String> addNewDeclareBelongYearConfig(
            @RequestBody
            @Validated({Groups.Add.class})
            TcpDeclareBelongYearConfigDTO tcpDeclareBelongYearConfigDTO) {
        tcpDeclareBelongYearConfigService.addNewDeclareBelongYearConfig(tcpDeclareBelongYearConfigDTO);
        return R.ok();
    }

    /**
     * 修改申报所属年度配置信息
     *
     * @param tcpDbycId                     配置id
     * @param tcpDeclareBelongYearConfigDTO 配置信息
     */
    @PutMapping("/declareBelongYear/{tcpDbycId}")
    public R<String> updateDeclareBelongYearConfig(
            @PathVariable(name = "tcpDbycId")
            ULong tcpDbycId,
            @RequestBody
            @Validated({Groups.Update.class})
            TcpDeclareBelongYearConfigDTO tcpDeclareBelongYearConfigDTO) {
        tcpDeclareBelongYearConfigService.UpdateDeclareBelongYearConfig(tcpDbycId, tcpDeclareBelongYearConfigDTO);
        return R.ok();
    }

}
